<?php
 include_once('../src/classes/class.mysql.php');
 session_start();
 $db = new MySQL();
 $comtec_id_machine = $_GET['comtec_id_machine'];
 $comtec_id_operation = $_GET['comtec_id_operation'];
 
 $result = $db->fetch_array($db->query("SELECT cod_mainteiner,comtec_id_configman FROM machines WHERE comtec_id_machine = $comtec_id_machine"));   
 $cod_mainteiner = $result['cod_mainteiner'];
 $comtec_id_configman = $result['comtec_id_configman'];
 
$result = $db->fetch_array($db->query(
     "SELECT CONCAT_WS(' ',r.name,r.lastname1,r.lastname2) as encargado,o.operation_type,
       DATE_FORMAT(m.date_next_maintenance,'%d/%m/%Y') as date_next,
       DATE_FORMAT(o.operation_date_start,'%d/%m/%Y') as operation_date1,
       TIME(o.operation_date_start) as operation_time1, 
       DATE_FORMAT(o.operation_date_end,'%d/%m/%Y') as operation_date2, 
       TIME(o.operation_date_end) as operation_time2,  
       o.diagnosis,o.changed_parts,o.value_parts,o.value_work,o.value_others,o.value_total,o.notes,o.notes_for_owner,
       o.delay,o.revised
      FROM (operation as o INNER JOIN machines as m ON o.comtec_id_machine=m.comtec_id_machine) INNER JOIN 
            responsible as r ON o.comtec_id_responsible = r.comtec_id_responsible WHERE comtec_id_operation = $comtec_id_operation"
));  
 $operation_type = $result['operation_type'];
 $encargado = $result['encargado'];
 
 $diagnosis = $result['diagnosis'];
 $changed_parts = $result['changed_parts'];
 $notes = $result['notes'];
 
 $date_next = $result['date_next'];
 $operation_date1 = $result['operation_date1'];
 $operation_time1 = $result['operation_time1'];
 $operation_time1 = substr($operation_time1,0,5);
 $operation_date2 = $result['operation_date2'];
 $operation_time2 = $result['operation_time2'];
 $operation_time2 = substr($operation_time2,0,5);
 $delay = $result['delay'];
 
 $value_parts = $result['value_parts'];
 $value_work = $result['value_work'];
 $value_others = $result['value_others'];
 $value_total = $result['value_total'];
 
 $notes_for_owner = $result['notes_for_owner'];
 $revised = $result['revised'];
 
     switch ($operation_type) {
      case 1: 
             $operation_type = "Mantenci&oacute;n";
      break;
      case 2: 
             $operation_type = "Emergencia";
      break; 
      case 3: 
             $operation_type = "Instalaci&oacute;n";
      break;
      case 4:
             $operation_type = "Reparaci&oacute;n";
      break;
     }
     
     switch ($revised) {
       case 0: $revised = "No";
       break;
       case 1: $revised = "Si";
       break;
     }
 
?>
<fieldset class="curved">
 <legend>Ver</legend>
 <table style="margin: 10px auto; border-spacing: 10px;">
        <tr>
            <td width="200"><label>M&aacute;quina</label></td>
            <td><input type="text" size="40" DISABLED id="cod_mainteiner" value="<?=$cod_mainteiner?>"/></td>
        </tr>
        <tr>
            <td width="200"><label>Tipo de operaci&oacute;n</label></td>
            <td><input type="text" size="40" DISABLED id="operation_type" value="<?=$operation_type?>"/></td>
            <td width="200"><label>Encargado</label></td>
            <td colspan="4"><input type="text" DISABLED size="40" value="<?=$encargado?>"/></td>
       </tr>
            <? if($_SESSION['users']!="clients"){ ?>
            <tr>
               <td width="200"><label>Diagn&oacute;stico</label></td>
               <td colspan=4><textarea rows="2" cols="91" readonly="readonly" style="resize:none"><?=$diagnosis?></textarea></td>
           </tr>
           <tr>
               <td width="200"><label>Repuestos cambiados</label></td>
               <td colspan=4><textarea id="changed_parts" rows="2" cols="91" readonly="readonly" style="resize:none"><?=$changed_parts?></textarea></td>
           </tr>
           <tr>
                <td width="200"><label>Notas</label></td> 
                <td colspan=4><textarea id="notes" rows="2" cols="91" readonly="readonly" style="resize:none"><?=$notes?></textarea></td>
           </tr>
           <? }?>
           <tr>
               <td width="200"><label>Fecha prox. Mantenci&oacute;n</label></td>
               <td><input type="text" size="40" DISABLED value="<?=$date_next?>"/>
               </td>
           </tr>
           <? if($_SESSION['users']=="administratives-2" || $_SESSION['users']=="managers"){ ?>
           <tr>
                <td width="200"><label>Valor mano de obra</label></td>
                <td><input type="text" size="40" DISABLED value="<?=$value_work?>"/>    
                </td> 
                <td width="200"><label>Valores repuestos</label></td>
                <td><input type="text" size="40" DISABLED value="<?=$value_parts?>"/>    
                </td>
           </tr>
           <tr>
                <td width="200"><label>Otros valores</label></td>
                <td><input type="text" size="40" DISABLED value="<?=$value_others?>"/></td>
                <td width="200"><label>Valor total</label></td>
                <td><input type="text" size="40" DISABLED value="<?=$value_total?>"/></td>
           </tr>
           <?}?>
           <? if($_SESSION['users']!="clients"){ ?>
           <tr>              
               <td width="200"><label>Fecha de inicio</label></td>
                   <td><input type="text" size="40" DISABLED value="<?=$operation_date1?>"/>                   
               </td>
               <td width="200"><label>Hora de inicio</label></td>
                   <td><input type="text" size="40" DISABLED value="<?=$operation_time1?>"/>
               </td>
           </tr>
           <? }?>
           <tr>
               <td width="200"><label>Fecha de fin</label></td>
                <td><input type="text" size="40" DISABLED value="<?=$operation_date2?>"/>                  
               </td>
               <td width="200"><label>Hora de fin</label></td>
               <td><input type="text" size="40" DISABLED value="<?=$operation_time2?>"/>                  
               </td> 
           </tr>
           <? if($_SESSION['users']=="administratives-2" || $_SESSION['users']=="managers"){ ?>
           <tr>
               <td width="200"><label>Demora</label></td>
               <td><input type="text" size="40" DISABLED value="<?=$delay?>"/></td>
           </tr>
           <?}?>
           <tr>              
               <td width="200"><label>Notas para cliente</label></td>
               <td colspan=4><textarea id="notes_for_owner" rows="2" cols="91" readonly="readonly" style="resize:none"><?=$notes_for_owner?></textarea>    
               </td>
           </tr>
            <? if($_SESSION['users']!="clients"){ ?>
           <tr><td width="200"><label>Revisado</label></td>
            <td><input type="text" size="40" DISABLED value="<?=$revised?>"/>
           </td></tr>
            <? }?>
           <tr><td><input type="button" value="Regresar" id="send" onclick='javascript:loadHome()' /></td></tr>
          </table> 
</fieldset>